package leetcode.array;

/**
 * @Description:
 * @Author Ammar
 * @Create 2023/9/13 17:17
 */
public class _剑指Offer11_旋转数组的最小数字 {
    public int minArray(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }

        int n = nums.length;
        int left = 0;
        int right = n - 1;
        while (left <= right) {
            int mid = left + ((right - left) << 1);
            // 中间比右边大，说明最小值在右边。
            if (nums[mid] > nums[right]) {
                left = mid + 1;
            } else if (nums[mid] < nums[right]) {
                right = mid;
            } else {
                right--;
            }
        }
        return left;
    }
}
